package com.camera.yl.v

//import com.yl.immodule.fragment.ChannelListFragment
import android.view.View
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentTransaction
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.camera.base.v.BaseActivity
import com.camera.routemodule.RouterPath
import com.camera.yl.R
import com.camera.yl.databinding.ActivityImBinding
import com.camera.yl.v.models.IMViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = RouterPath.path.im_activity)
class IMActivity : BaseActivity<ActivityImBinding,IMViewModel>() {
    override val viewModelClass: Class<IMViewModel>
        get() = IMViewModel::class.java
    private var onRightClickListener: OnRightClickListener? = null
    private var fragment: Fragment? = null
    override fun getLayoutId(): Int {
        return R.layout.activity_im
    }

    override fun getStatusBarColor(): Int {
        return R.color.title_background_color
    }

    override fun loadData() {
        mBinding.viewModel = viewModel
    }

    override fun initView() {
        val type = intent.getStringExtra("fragment_key")

        when (type) {
            "contacts" -> {
                mBinding.title = getString(R.string.contacts_fragment)
                mBinding.rightText = ""
                fragment = ARouter.getInstance().build(RouterPath.path.contacts_fragment).navigation() as Fragment
            }
            "chat" -> {
                mBinding.title = getString(R.string.message_fragment_ts)
                mBinding.rightText = ""
                fragment = ARouter.getInstance().build(RouterPath.path.message_fragment).navigation() as Fragment
            }
            "channel" -> {
                mBinding.title = getString(R.string.channl_fragment)
                fragment = ARouter.getInstance().build(RouterPath.path.channel_fragment).navigation() as Fragment
            }
            "channel_settings" -> {
                mBinding.title = getString(R.string.channel_settings_fragment)
                mBinding.rightText = ""
                fragment = ARouter.getInstance().build(RouterPath.path.channel_settings_fragment).navigation() as Fragment
            }
            "ptt" -> {
                mBinding.title = getString(R.string.ptt_fragment)
                mBinding.rightText = ""
                fragment = ARouter.getInstance().build(RouterPath.path.ptt_fragment).navigation() as Fragment
            }
        }
        mBinding.rightClickListener = View.OnClickListener {
//            if (fragment is ChannelListFragment) {
//                (fragment as ChannelListFragment).startAddChannel();
//            }
        }
        fragment?.let {
            val fragmentManager: FragmentManager = supportFragmentManager
            val fragmentTransaction: FragmentTransaction = fragmentManager.beginTransaction()
            fragmentTransaction.replace(R.id.fl_activity_im, it)
            fragmentTransaction.commit()
        }
    }

    interface OnRightClickListener {
        fun startAddChannel()
    }
}